package LeetCodeHot100TopInterview;

public class Q141_CircleLink {
    //环形链表 ==> 判断是否有环
    //腾讯
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null){
            return false;
        }

        //快慢指针
        ListNode slow = head;
        ListNode fast = head.next;


        while (slow != fast){
            if (slow == null || fast == null || fast.next == null){
                return false;
            }
            slow = slow.next;
            fast = fast.next.next;
        }

        return true;
    }

}
